package com.geekcoding.geekoj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geekcoding.geekoj.entity.Question;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface QuestionMapper extends BaseMapper<Question> {

    @Select("select q.* from geekoj_question q " +
            "left join (select * from geekoj_test_answer where test_id = #{testId} and answer_id = #{userId}) a " +
            "on q.id = a.question_id " +
            "where subject_id = #{subjectId} and a.id is null order by create_time asc limit 1")
    Question nextSequenceQuestion(String subjectId, String testId, String userId);

    @Select("select q.* from geekoj_question q " +
            "left join (select * from geekoj_test_answer where test_id = #{testId} and answer_id = #{userId}) a " +
            "on q.id = a.question_id " +
            "where subject_id = #{subjectId} and a.id is null order by RAND() asc limit 1")
    Question nextRandomQuestion(String subjectId, String testId, String userId);
}
